const express = require('express')
const Mock = require('mockjs')
const router = express.Router()

const departments = ['内科', '外科', '五官科', '儿科', '消化内科', '骨科', '康复科']
const titles = ['住院医师', '主治医师', '副主任医师', '主任医师']

// 获取科室信息
router.get('/:id?', (req, res) => {
  const { id } = req.params
  if (id) {
    res.json({
      code: 200,
      data: Mock.mock({
        id,
        'name': '@cname',
        'title|1': titles,
        'time|1': ['@date("yyyy-MM-dd") 上午', '@date("yyyy-MM-dd") 下午'],
        'department': {
          id: departmentId,
          'name|1': departments
        },
        'fee|5-15': 5,
      })
    })
  } else {
    const { departmentId } = req.query
    const len = departmentId ? '6-12' : '30-45'
    let department

    if (departmentId) {
      department = {
        id: departmentId,
        name: departments[(departmentId - 1)%departments.length]
      }
    } else {
      department = {
        'id|+1': 1,
        'name|1': departments
      }
    }

    res.json({
      code: 200,
      data: Mock.mock({
        [`list|${len}`]: [{
          'id|+1': 1,
          'name': '@cname',
          'title|1': titles,
          'time|1': ['@date("yyyy-MM-dd") 上午', '@date("yyyy-MM-dd") 下午'],
          department,
          'fee|5-15': 5,
        }],
        total: len
      })
    })
  }
})

module.exports = router
